home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3000 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  69 lines

  1. Path: kettle.magna.com.au!4
  2. From: techteam@stratem.com.au (Technical Team)
  3. Newsgroups: comp.lang.c++
  4. Subject: Borland C++ 4.52 - problems with tellg & ftell
  5. Date: Thu, 18 Jan 96 15:06:33 GMT
  6. Organization: Stratem Group
  7. Message-ID: <4dk2qh$se7@kettle.magna.com.au>
  8. NNTP-Posting-Host: techteam.magna.com.au
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. PROBLEM WITH istream:: tellg() using Borland C++ 4.52 WIN 32
  12.  
  13. We have made a function called SkipHash which should test if a line 
  14. is starting with a '#", and if it is, skip the line. The function 
  15. should move the stream pointer to the beginning of the first line not 
  16. starting with '#'. But function istream:: tellg is not always 
  17. returning the correct current position, so function istream::seekg is 
  18. not correctly positioning the file pointer. We have not had the same 
  19. problem running under WIN 16, but we have had the same problem 
  20. using ftell function and file handles under WIN 32.
  21.  
  22. Has anyone else had problems using tellg or ftell using Borland with 
  23. WIN 32 ?
  24.  
  25. Code for my function is:
  26. // Checks for '#' character
  27. // Goes to the beginning of the first line not starting with '#'
  28. // If it reaches end of file before this it returns 1
  29. // If successful returns 0
  30.  
  31. int SkipHash(ifstream& fstream)
  32. {
  33.     char szTemp[256];
  34.  
  35.     int a =  fstream.tellg();
  36.  
  37.     char ch = fstream.get();
  38.  
  39.     while(ch == '\n' || ch == ' ' || ch == '\t' || ch == '#' || 
  40. ch == EOF)
  41.     {
  42.         if(ch == EOF)
  43.             return 1;
  44.         else if(ch == '#')
  45.         {
  46.             // Reads line of text
  47.             ReadLine(fstream, szTemp);
  48.             a = fstream.tellg();
  49.             ch = fstream.get();
  50.         }
  51.         else
  52.         {
  53.             a = fstream.tellg();
  54.             ch = fstream.get();
  55.         }
  56.     }
  57.  
  58.     fstream.seekg(a);
  59.     return 0;
  60. }
  61.  
  62. Please let me know if you can see anything wrong with this code.
  63.  
  64. Michael Lang
  65. Manager Systems Development
  66.  
  67. P.S I've reposted this article as our email address was incorrectly 
  68. displayed in the last article
  69.